package com.server.web.controller.pinggu;

import com.alibaba.fastjson.JSONObject;
import com.server.common.annotation.Log;
import com.server.common.core.controller.BaseController;
import com.server.common.core.domain.AjaxResult;
import com.server.common.core.domain.model.LoginUser;
import com.server.common.core.page.TableDataInfo;
import com.server.common.enums.BusinessType;
import com.server.pinggu.domain.SenFormsRemark;
import com.server.pinggu.service.ISenFormsRemarkService;
import com.server.system.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 评估管理员备注Controller
 * 
 * @author ltao
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/sen/forms/remark")
public class SenFormsRemarkController extends BaseController
{
    @Autowired
    private ISenFormsRemarkService senFormsRemarkService;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    /**
     * 查询评估管理员备注列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SenFormsRemark senFormsRemark)
    {
        List<JSONObject> list = senFormsRemarkService.queryList(senFormsRemark);
        return getDataTable(list);
    }


    /**
     * 获取评估管理员备注详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(senFormsRemarkService.getById(id));
    }

    /**
     * 新增评估管理员备注
     */
    @Log(title = "评估管理员备注", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SenFormsRemark senFormsRemark)
    {
        LoginUser loginUser = getLoginUser();
        senFormsRemark.setUserid(loginUser.getUserId());
        List<Long>  ids = sysUserRoleMapper.selectByUserId(loginUser.getUserId());
        senFormsRemark.setCtype((ids.contains(1L) || ids.contains(2L))? 2:1);
        senFormsRemark.setDttime(new Date());
        return toAjax(senFormsRemarkService.save(senFormsRemark));
    }

    /**
     * 修改评估管理员备注
     */
    @Log(title = "评估管理员备注", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SenFormsRemark senFormsRemark)
    {
        return toAjax(senFormsRemarkService.updateById(senFormsRemark));
    }

    /**
     * 删除评估管理员备注
     */
    @Log(title = "评估管理员备注", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(senFormsRemarkService.removeByIds(Arrays.asList(ids)));
    }
}
